#include <stdio.h>

int maxProfit(int* prices, int pricesSize) {
    int r=0;
    for( int i=1; i<pricesSize; i++ )
        r=r+ ((prices[i]>prices[i-1])?prices[i]-prices[i-1]:0);
    return r;
}

int main(){
    //int p[]={7,1,5,3,6};
    //int p[]={1,2,3,4,5};
    int p[]={7,6,4,3,1};
    printf("%d\n",maxProfit(p,sizeof(p)/sizeof(int)));
    return 0;
}
